<template>
</template>

<script>
	import {loginWx} from '@/api/api.js'
	export default{
		data(){
			return{
				op:null
			}
		},
		methods:{
			init(){
				let _this = this
				if(this.op==null){
					uni.showToast({
						title:'授权失败，2S后返回首页',
						icon:'none',
						duration:3000
					})
					setTimeout(()=>{
						_this.$navigateTo({url:'/'})
					},2000)
				}
				loginWx(this.op).then(res=>{
					console.info(res)
					if(res.code == 0){
						// avatar: "https://qiance.qianfanyun.com/front2_0_Fme5oiuLcMjyuYTMDy6SHJ45AX5c.1626684765.jpg?imageslim|imageView2/1/w/100/h/100"
						// expire: 2592000
						// headimgurl: "https://thirdwx.qlogo.cn/mmopen/vi_32/6p7YWGXJhrHN7gI0dFtxA73djtxQGMq7PkR74cJEicuToYdF8ab6OSiavEZhbialxxrwVjjO9SdkxuRQuTbStDmhQ/132"
						// id: 5
						// token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOjUsInVpZCI6MzkyMSwiaWF0IjoxNjY3OTYxMzgwLCJleHAiOjE2NzA1NTMzODAsIm5iZiI6MTY2Nzk2MTM4MH0.Dli4dVkqrXEzK7H8F8_vK5PMO_PJ5yaejAdieh8VXNI"
						// uid: "3921"
						// username: "问就是不会！"
						let actid = uni.getStorageSync('actid')
						let urlData = JSON.parse(uni.getStorageSync('rUrl'))
						uni.setStorageSync(urlData.id+'bearerToken',res.data.token)
						uni.setStorageSync(urlData.id+'bearerToken_expire',res.data.expire+Date.parse(new Date())/1000)
						uni.setStorageSync('icon'+actid,res.data.avatar)
						uni.setStorageSync('iconWx'+actid,res.data.headimgurl)
						uni.setStorageSync('wechatInfo'+actid,res.data)
						let skinType = uni.getStorageSync(actid+'SkinType') || null
						this.$store.commit("SET_SKINTYPE",skinType)
						this.$store.dispatch('setLoginInfo',res.data)
						// this.$navigateTo({url:urlData.rUrl})

						// return
						window.location.href = window.location.origin + '/plugin-view'+urlData.rUrl
					}else{
						uni.showToast({
							title:'code：'+res.code+'；text:'+res.text
						})
					}
				})
			}
		},
		mounted() {
			this.init()
			this.$setTitle('正在登录')
		},
		onLoad(op) {
			this.op = op
		}
	}
</script>

<style>
</style>